﻿using System.Xml.Linq;
using Xunit;
using Xunit.Should;

namespace Adjunct.Framework.Nuspec
{
	public class NuspecIncludesSpec
	{
		private const string ValidXml = "<files><file src='source1.txt' /><file src='source2.*' target='content' /></files>";

		private readonly NuspecInclude _include1 = new NuspecInclude("source1.txt");
		private readonly NuspecInclude _include2 = new NuspecInclude("source2.*", "content");

		[Fact]
		public void EmptyToXElement()
		{
			NuspecIncludes includes = new NuspecIncludes();
			((XElement)includes).ShouldBeNull();
		}

		[Fact]
		public void FromEmptyXElement()
		{
			XElement element = XElement.Parse("<files />");
			NuspecIncludes includes = ((NuspecIncludes)element);
			includes.ShouldNotBeNull();
			includes.ShouldBeEmpty();
		}

		[Fact]
		public void FromNullXElement()
		{
			XElement element = null;
			NuspecIncludes includes = ((NuspecIncludes)element);
			includes.ShouldNotBeNull();
			includes.ShouldBeEmpty();
		}

		[Fact]
		public void FromValidXElement()
		{
			XElement element = XElement.Parse(ValidXml);
			((NuspecIncludes)element).ShouldEqual(new NuspecIncludes {
				_include2,
				_include1
			});
		}

		[Fact]
		public void NullToXElement()
		{
			NuspecIncludes includes = null;
			((XElement)includes).ShouldBeNull();
		}

		[Fact]
		public void ValidToXElement()
		{
			NuspecIncludes includes = new NuspecIncludes {
				_include1,
				_include2
			};
			((XElement)includes).ShouldEqual(ValidXml);
		}
	}
}